// https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/


class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_map<char, int> hash;
        int n = s.size();
        int len = -1;
        for(int i = 0, j = 0; j < n;) {
            hash[s[j]] += 1;
            while(hash[s[j]] > 1) {     
                hash[s[i++]]--;
            }
            len = max(len, j - i + 1);
            j++;
        }
        return len == -1 ? 0 : len;
    }
};